package com.runssnail.huafeiduo.api.request.phone;

import com.runssnail.huafeiduo.api.request.GetRequest;
import com.runssnail.huafeiduo.api.response.phone.OrderPhoneSubmitResponse;

import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * 下单接口，下单后接口会立即返回成功，如遇运营商维护等情况，会立即返回失败。
 * 当一笔订单处理完成后 话费多会向notify_url[如果提交订单时传入了此参数]发送异步通知，告知商户充值结果 详情见回调结果
 * <p>
 * Created by zhengwei on 2016/3/31.
 */
public class OrderPhoneSubmitRequest extends GetRequest<OrderPhoneSubmitResponse> {

    private static final long serialVersionUID = -4694874327722997825L;

    /**
     * 面值单位分
     */
    private Long cardWorth;

    /**
     * 要充值的手机号码
     */
    private String mobile;

    /**
     * 商户接收充值结果的回调地址
     */
    private String notifyUrl;

    /**
     * 商户订单号
     */
    private String spOrderId;

    /**
     * @param cardWorth 面值
     * @param mobile    手机
     * @param spOrderId   订单号
     */
    public OrderPhoneSubmitRequest(Long cardWorth, String mobile, String spOrderId) {
        this(cardWorth, mobile, spOrderId, null);
    }

    /**
     * @param cardWorth 面值
     * @param mobile    手机
     * @param spOrderId  商户订单号
     * @param notifyUrl 通知url
     */
    public OrderPhoneSubmitRequest(Long cardWorth, String mobile, String spOrderId, String notifyUrl) {
        this.cardWorth = cardWorth;
        this.mobile = mobile;
        this.spOrderId = spOrderId;
        this.notifyUrl = notifyUrl;
    }

    public Long getCardWorth() {
        return cardWorth;
    }

    public void setCardWorth(Long cardWorth) {
        this.cardWorth = cardWorth;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getNotifyUrl() {
        return notifyUrl;
    }

    public void setNotifyUrl(String notifyUrl) {
        this.notifyUrl = notifyUrl;
    }

    public String getSpOrderId() {
        return spOrderId;
    }

    public void setSpOrderId(String spOrderId) {
        this.spOrderId = spOrderId;
    }

    @Override
    public String getApiUrl() {
        return "http://api.huafeiduo.com/gateway.cgi?mod=order.phone.submit";
    }

    @Override
    public Map<String, Object> getParams() {
        SortedMap<String, Object> params = new TreeMap<>();

        params.put("card_worth", this.cardWorth);
        params.put("phone_number", this.mobile);
        params.put("notify_url", this.notifyUrl);
        params.put("sp_order_id", this.spOrderId);

        return params;
    }

    @Override
    public Class<OrderPhoneSubmitResponse> getResponseClass() {
        return OrderPhoneSubmitResponse.class;
    }
}
